//
//  AY_UseListCell.m
//  AiYue
//
//  Created by boWen on 2023/12/22.
//

#import "AY_UseListCell.h"

@interface AY_UseListCell ()
@property (nonatomic,strong) UIView * bg_View;//底部圆角
@property (strong,nonatomic) UILabel *topTitleLabel;
@property (strong,nonatomic) UILabel *downTitleLabel;
@property (strong,nonatomic) UILabel *topRightLabel;
@property (strong,nonatomic) UILabel *downRightLabel;


@end

@implementation AY_UseListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addAllSubviewsWithUI];
    }
    return self;
}


- (void)addAllSubviewsWithUI {
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.contentView.backgroundColor = COLOR_Bg;
    
    self.bg_View = [AYTool createViewWithFrame:CGRectZero andBg:[UIColor whiteColor] andRadius:YNUM(6) andAddSubView:self.contentView];
    [self.bg_View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.equalTo(self.contentView);
    }];

    self.topTitleLabel = [AYTool createLabelWithFrame:CGRectZero andText:@"" andTextColor:COLOR(@"#909090") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(12)] andLines:1 andRadius:0 andAddSubView:self.bg_View];
    [self.topTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.bg_View).offset(YNUM(-8));
        make.left.equalTo(self.bg_View).offset(YNUM(12));
        make.height.offset(YNUM(20));
    }];
    
    self.downTitleLabel = [AYTool createLabelWithFrame:CGRectZero andText:@"" andTextColor:COLOR(@"#909090") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(12)] andLines:4 andRadius:0 andAddSubView:self.bg_View];
    [self.downTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topTitleLabel.mas_bottom).offset(YNUM(4));
        make.left.equalTo(self.bg_View).offset(YNUM(12));
        make.height.offset(YNUM(12));
    }];
    
    self.topRightLabel = [AYTool createLabelWithFrame:CGRectZero andText:@"" andTextColor:COLOR(@"#000002") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(20)] andLines:1 andRadius:0 andAddSubView:self.bg_View];
    [self.topRightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.bg_View).offset(YNUM(-8));
        make.right.equalTo(self.bg_View).offset(YNUM(-12));
        make.height.offset(YNUM(20));
    }];
    
    self.downRightLabel = [AYTool createLabelWithFrame:CGRectZero andText:@"已到账" andTextColor:COLOR(@"#909090") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(12)] andLines:4 andRadius:0 andAddSubView:self.bg_View];
    [self.downRightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topRightLabel.mas_bottom).offset(YNUM(4));
        make.right.equalTo(self.bg_View).offset(YNUM(-12));
        make.height.offset(YNUM(12));
    }];
    
}

- (void)setModel:(AssetRecordModel *)model {
    _model = model;
    self.topTitleLabel.text = kStringUtils(_model.title);
    if (!kStringIsEmpty(_model.gmtCreate)) {
        NSString *time = [_model.gmtCreate stringByReplacingOccurrencesOfString:@"T" withString:@" "];
        self.downTitleLabel.text = time;
    }
    if ([kStringUtils(_model.recordDir) isEqualToString:@"1"]) {
        if (kStringIsEmpty(model.assetAmount)) {
            self.topRightLabel.text = @"0";
        }else {
            self.topRightLabel.text = [NSString stringWithFormat:@"+%0.2f",model.assetAmount.floatValue];
        }
    }else if ([kStringUtils(_model.recordDir) isEqualToString:@"2"]) {
        if (kStringIsEmpty(model.assetAmount)) {
            self.topRightLabel.text = @"0";
        }else {
            self.topRightLabel.text = [NSString stringWithFormat:@"-%0.2f",model.assetAmount.floatValue];
        }
    }else {
        if (kStringIsEmpty(model.assetAmount)) {
            self.topRightLabel.text = @"0";
        }else {
            self.topRightLabel.text = [NSString stringWithFormat:@"%0.2f",model.assetAmount.floatValue];
        }
    }
}


@end
